Repository navigation
Add --target for scanning an address without a target file - #37
Merged
Merged
Conversation
This was referenced Aug 21, 2026
Closes #4. Requested in Jan 2021 and attempted in PR #12, which could not be applied: its fork is gone and the code it patched has since been restructured. Its approach also overwrote ranges.txt in place, unvalidated, from a prompt that fired even in config-file mode where the written file is never read. --target accepts a comma-separated list of anything a target file line accepts (bare IP, CIDR, A-B range, address netmask) and takes precedence over both config.json's target_file and the interactive prompt, so it works in fully non-interactive runs. Three properties the earlier attempt lacked: - ranges.txt is never touched. It is the operator's engagement scope input, tracked in-repo as an empty template. Addresses go to cli_targets.txt in output_path via _atomic_write(), which also leaves a record of what each run actually targeted. - The value is validated before anything else happens, and a bad entry exits non-zero naming the token. Accepting a typo would produce a clean run over an empty target set — a false negative with a report attached. - Validation reuses the target-file parser. _parse_range_line() is extracted from _parse_target_ranges() so the CLI cannot accept syntax the scan then fails to read; the extraction is behaviour-preserving, including the silent skip of unparseable lines and the IPv6 file/line warning. _resolve_cli_target() holds the argv-to-tokens glue so the reject path is tested: main() is an interactive entry point excluded from coverage. 939 tests pass (32 new), 100% coverage. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
bandrel
force-pushed
the
feat/target-flag
branch
from
August 21, 2026 16:25
1e4ac89 to
1cd3a1e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4. Replaces #11's sibling PR #12, which I closed as unmergeable.
Why not just apply #12
#4 was filed in Jan 2021 and #12 tried to implement it two months later. It can't be applied: the source fork has been deleted and the code it patched has since been restructured (the config load it anchored to now lives in
_load_config()).Its approach also had three problems that matter more now than they did then:
ranges.txtin place, without confirmation. That file is the engagement scope input and is tracked in-repo as a deliberately empty template.target_filecomes from JSON andranges.txtis never read. It would prompt, accept an address, and silently have no effect.What this does
The value accepts anything a target file line accepts — bare IP, CIDR,
A-Brange,address netmask— comma-separated. It takes precedence over bothconfig.json'starget_fileand the interactive prompt, so unlike a prompt-based approach it works in fully non-interactive runs.Three properties worth calling out, each addressing one of the above:
ranges.txtis never touched. Addresses are written tocli_targets.txtunderoutput_pathvia_atomic_write(). That keeps the operator's scope file intact and leaves a record on disk of what each run actually targeted. There's a test asserting a pre-existingranges.txtis byte-for-byte unchanged.Validation happens before anything else, and a bad entry exits non-zero naming the offending token. Silently accepting a typo would produce a clean run over an empty target set — a false negative with a report attached, which is this tool's worst outcome.
--target --resumeis also rejected rather than consuming the next flag as an address.Validation reuses the target-file parser.
_parse_range_line()is extracted from_parse_target_ranges()so the CLI cannot accept syntax the scan then fails to read. Two parsers would drift, and the drift would surface as a target accepted at the command line and silently not scanned. The extraction is behaviour-preserving — including the silent skip of unparseable lines (masscan accepts forms this parser doesn't model, and the same function runs on the exclusions file) and the IPv6 file/line warning; both have tests pinning them._resolve_cli_target()holds the argv-to-tokens glue rather than inlining it inmain(), so the reject path is testable —main()carries a pre-existing# pragma: no coveras an interactive entry point.Verification
pragmareferenced above is pre-existing onmain().Round-trip is tested explicitly: what
--targetwrites is parsed back by_parse_target_ranges()and asserted to produce the expected integer bounds.🤖 Generated with Claude Code